import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path";
 
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  const { VITE_APP_ENV, VITE_PUBLIC_PATH, VITE_APP_BASE_API, VITE_APP_URL } = env
 
  return {
    base: VITE_APP_ENV === 'development' ? '/' : VITE_PUBLIC_PATH + '/',
    publicPath: VITE_APP_ENV === 'development' ? '/': VITE_PUBLIC_PATH + '/',
    indexPath: 'index.html',
    plugins: [
      vue(),
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
      },
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
    },
    server: {
      port: 80,
      host: true,
      hmr:true,
      open: true,
      proxy: {
        [VITE_APP_BASE_API]: {
          target: VITE_APP_URL,
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/dev-api/, ''),
        },
      },
    }
  }
})